package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface ClazzMapper {

    /**
     * 根据id删除班级
     * @param id
     */

    @Delete("delete from clazz where id = #{id}")
    void deleteById(Integer id);

    /**
     * 查询所有班级
     * @return
     */
    //@Select("select * from clazz")
    @Select("select id, name, room, begin_date, end_date, master_id, subject, create_time, update_time from clazz")
    List<Clazz> selectAll();

    /**
     * 添加班级
     * @param clazz
     * @return
     */
    @Insert("insert into clazz(name, room, begin_date, end_date, master_id, subject, create_time, update_time)" +
            " values (#{name}, #{room},#{beginDate},#{endDate},#{masterId},#{subject},#{createTime},#{updateTime})")
    int insert(Clazz clazz);


    /**
     * 班级分页查询
     * @param clazzQueryParam
     * @return
     */
    Page<Clazz> list(ClazzQueryParam clazzQueryParam);

    /**
     * 根据id查询班级
     * @param id
     */
    @Select("select * from clazz where id = #{id}")
    Clazz getById(Integer id);

    /**
     * 修改班级信息
     * @param clazz
     */
    @Update("update clazz set id = #{id},name = #{name},room = #{room},begin_date = #{beginDate},end_date = #{endDate},master_id = #{masterId},subject = #{subject} where id = #{id}")
    void update(Clazz clazz);

    //查询该班级下有多少个班级
    @Select("select count(*) from clazz where master_id = #{id}")
    int clazzcount(Integer id);



    List<Clazz> findAll();
}
